package org.grow.yc.filter;

import org.apache.catalina.connector.RequestFacade;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: xwg
 * @CreateDate: 2024/9/27
 */

//Filter
//@Component
public class ExampleFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException {
        System.out.println("*************");
        System.out.println("*************");
//        System.out.println(servletRequest.getClass());
//        System.out.println(servletRequest instanceof HttpServletRequest);

        HttpServletRequest request=  (HttpServletRequest) servletRequest;
        HttpServletResponse response=  (HttpServletResponse)servletResponse;
        String uri =  request.getRequestURI();
        System.out.println(uri);
        if(uri.contains("static")){
            //        过关
            filterChain.doFilter(servletRequest, servletResponse);
        }else {
            System.out.println("不放行 ");
            response.setStatus(888);
            response.getWriter().println("not allowed 不放行");
            return;
        }

    }
}